package com.gxuwz.medical.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.List;

import com.gxuwz.medical.domain.family_member.Family_member;
import com.gxuwz.medical.exception.DbException;

public class Family_memberDAO extends GenericDao<Family_member> {
	protected Family_member handle(ResultSet rs) throws SQLException {

		String join_nh_code = rs.getString("join_nh_code");// 农合证号
		String familycode = rs.getString("familycode");// 家庭编号
		String membername = rs.getString("membername");// 姓名
		String IDcard = rs.getString("IDcard");// 身份证号码
		String state = rs.getString("state");// 人员属性
		String relation = rs.getString("relation");// 与 户 主 关系
		Timestamp createtime = rs.getTimestamp("createtime");
		String userid = rs.getString("userid");
		String familyteam = rs.getString("familyteam");// 户 内编号
		String age = rs.getString("age");
		String birthday = rs.getString("birthday");
		String tel = rs.getString("tel");
		String health = rs.getString("health");
		String nation = rs.getString("nation");
		String sex = rs.getString("sex");
		String IScountryside = rs.getString("IScountryside");
		String occupation = rs.getString("occupation");// 职业
		String address = rs.getString("address");
		String medicalCard = rs.getString("medicalCard");
		String ch_year = rs.getString("ch_year");
		Family_member entity = new Family_member(join_nh_code, familycode, membername, IDcard, state, relation,
				createtime, userid, familyteam, age, birthday, tel, health, nation, sex, IScountryside, occupation,
				address, medicalCard, ch_year);
		return entity;
	}

	public List<Family_member> findFamilyList(String familycode) throws DbException {
		try {
			String sql = "select * from t_family_member AS f  where 1=1 and f.familycode='" + familycode
					+ "' ORDER BY f.ch_year";

			Object[] params = {};

			return super.queryOjects(sql, params);

		} catch (SQLException e) {
			throw new DbException("按级别查找行政区域失败!", e);
		}
	}

	public List<Family_member> findFamilyByJoin_nh_code(String join_nh_code) throws DbException {
		try {
			String sql = "select * from t_family_member where 1=1 and join_nh_code='" + join_nh_code + "'";

			Object[] params = {};

			return super.queryOjects(sql, params);

		} catch (SQLException e) {
			throw new DbException("按级别查找行政区域失败!", e);
		}
	}

	public List<Family_member> findByKeyValue(String key, String value) throws DbException {
		try {
			String sqlSB = "";
			StringBuffer sb = new StringBuffer(1024);
			if (key != null && value != null) {
				sqlSB = sb.append(" and " + key + "='" + value + "'").toString();
			}
			String sql = "select * from t_family_member where 1=1 " + sqlSB + "";
			System.out.println(sql);
			Object[] params = {};

			return super.queryOjects(sql, params);

		} catch (SQLException e) {
			throw new DbException("慢性病证信息查询失败!", e);
		}
	}

}
